package com.leyou.item.client;

import com.leyou.common.vo.PageResult;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * feign的接口
 */
@FeignClient("item-service")  //标识当前是item服务的Feign客户端
public interface ItemClient {

    /**
     * 分页查询spu信息
     * @param page
     * @param rows
     * @param key
     * @param saleable
     * @return
     */
    @GetMapping("/spu/page")
    PageResult<SpuDTO> findSpuByPage(@RequestParam(name = "page",defaultValue = "1")Integer page,
                                     @RequestParam(name = "rows",defaultValue = "5")Integer rows,
                                     @RequestParam(name = "key",required = false)String key,
                                     @RequestParam(name = "saleable",required = false)Boolean saleable);

    /**
     * 根据spuid 查询sku集合
     * @param spuId
     * @return
     */
    @GetMapping("/sku/of/spu")
    List<SkuDTO> findSkuListBySpuId(@RequestParam(name = "id")Long spuId);

    @GetMapping("/spec/params")
    List<SpecParamDTO> findSpecParamListByCondition(@RequestParam(name = "cid",required = false)Long cid,
                                                   @RequestParam(name = "gid",required = false)Long gid,
                                                   @RequestParam(name = "searching",required = false)Boolean searching);
    /**
     * 根据spuid 查询spudetail对象
     * @param spuId
     * @return
     */
    @GetMapping("/spu/detail")
    SpuDetailDTO findSpuDetailBySpuId(@RequestParam(name = "id")Long spuId);

    /**
     * 根据cid集合获取分类集合
     * @param cids
     * @return
     */
    @GetMapping("/category/list")
    List<CategoryDTO> findCategoryListByIds(@RequestParam(name = "ids")List<Long> cids);

    /**
     * 根据id集合查询品牌集合
     * @param brandIds
     * @return
     */
    @GetMapping("/brand/list")
    List<BrandDTO> findBrandListByIds(@RequestParam(name = "ids")List<Long> brandIds);

    /**
     * 根据主键id查询spu对象
     * @param spuId
     * @return
     */
    @GetMapping("/spu/{id}")
    SpuDTO findSpuById(@PathVariable(name = "id")Long spuId);

    /**
     * 根据主键id 查询品牌对象
     * @param brandId
     * @return
     */
    @GetMapping("/brand/{id}")
    BrandDTO findBrandById(@PathVariable(name = "id")Long brandId);

    /**
     * 根据cid 查询 规格组 和 组内参数的集合
     * @param cid
     * @return
     */
    @GetMapping("/spec/of/category")
    List<SpecGroupDTO> findSpecGroupByCid(@RequestParam(name = "id")Long cid);

    /**
     * 根据id集合查询sku的集合
     * @param skuIds
     * @return
     */
    @GetMapping("/sku/list")
    List<SkuDTO> findSkuListByIds(@RequestParam(name = "ids")List<Long> skuIds);

    /**
     * 减库存操作
     * @param skuIdNumMap
     */
    @PutMapping("/sku/minusStock")
    void minusStock(@RequestBody Map<Long, Integer> skuIdNumMap);

    /**
     * 恢复库存
     * @param skuIdNumMap
     */
    @PutMapping("/sku/plusStock")
    void plusStock(@RequestBody Map<Long, Integer> skuIdNumMap);
}
